package com.ax.action.system;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.ax.pojo.TabLable;
import com.ax.service.TabLableService;
import com.ax.utils.BaseAction;
import com.ax.utils.PageInfo;

@Controller("tabLableAction")
public class TabLableAction extends BaseAction {
	
	private TabLableService tabLableService;

	@Resource(name="tabLableService")
	public void setTabLableService(TabLableService tabLableService) {
		this.tabLableService = tabLableService;
	}
	
	private PageInfo page;
	
	public PageInfo getPage() {
		return page;
	}

	public void setPage(PageInfo page) {
		this.page = page;
	}

	public String findLists(){
		String code="";
		if (page==null) {
			page=new PageInfo();
		}
		String lName=request.getParameter("lName");
		if (lName!=null&&!"".equals(lName)) {
			 code=" and po.lname='"+lName+"'";
		}
		page=tabLableService.findPageInfo(page.getCurPage(), code);
		return "lable_list";
	}

	
	public String save(){
		  String lname=request.getParameter("lname").trim();
		  String linfo=request.getParameter("linfo").trim();
		  String lcode=request.getParameter("lcode").trim();
		  TabLable lable=new TabLable("{My:"+lname+"}", linfo, lcode);
		  tabLableService.saveTabLable(lable);
		return "lablelists";
	}
	
	
	public String update(){
		String lname=request.getParameter("lname");
		String linfo=request.getParameter("linfo");
		String lcode=request.getParameter("lcode");
		int lid=Integer.parseInt(request.getParameter("lid"));
		TabLable lable=new TabLable(lname, linfo, lcode);
		lable.setLid(lid);
		tabLableService.updateTabLable(lable);
		return "lablelists";
	}
	
	public String get(){
		int lid=Integer.parseInt(request.getParameter("lid"));
		TabLable lable=tabLableService.getTabLable(lid);
		request.setAttribute("lable",lable);
		return "update";
	}
	public String del(){
		int lid=Integer.parseInt(request.getParameter("lid"));
		TabLable lable=tabLableService.getTabLable(lid);
		tabLableService.delTabLable(lable);
		return "lablelists";
	}
}
